#ifndef AGORA_Buffer
# define AGORA_Buffer

#include <list>
#include <vector>
#include <iostream>
#include "IBuffer.h"



class Buffer : public IBuffer
{
public:
	Buffer(unsigned int size);
	~Buffer();
	virtual int Write(void *data, unsigned int size);
	virtual void*  Read(unsigned int size, bool delDataReaded = true);
	virtual void   Delete(unsigned int size);
	virtual unsigned int Size();
	virtual unsigned int SizeMax();
	virtual void Clean();
	virtual void SetEvent(bool status);
	virtual void SubscribeEnoughData(ActOnBuffer function, unsigned int size, void *);
	virtual void UnsubscribeEnoughData(ActOnBuffer function, unsigned int size);
private:
	char *_data;
	
	unsigned int _currentStart;
	unsigned int _end;
	unsigned int _sizeMax;
	unsigned int _size;
	unsigned int _minSizeEvent;
	bool		 _checkEvent;
	struct EventOnEnoughData
	{
		ActOnBuffer function;
		unsigned int size;
		void *_udata;
	};
	std::list<EventOnEnoughData*> _listEventOnEnoughData;
};

#endif